package com.example.toutiao.base;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by admin on 2017/11/14.’
 * Fragmgent基类
 * 1. 初始化布局 initView();
 * 2. 初始化数据 initData();
 */

public abstract class BaseFragment extends Fragment {

    //这个Activity就是MainActivity
    public Activity myActivity;

    //Fragment被创建
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        myActivity = getActivity(); //获取fragment所在的Activity对象
    }

    //初始化Fragment布局
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = initView();
        return view;
    }

    //Activity创建结束
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        initData();
    }

    //初始化布局，子类必须实现
    public abstract View initView();

    //初始化数据，子类可以不实现
    public void initData(){

    };

}
